<?php
/**
 * Create By: PhpStorm
 * User: yuanxuncheng
 * File: GetAnnouncement.php
 * Date: 2017/1/2
 * Time: 23:13
 */

namespace app\api\model\page\announcement;

use app\api\model\dao\Announcement;
use app\library\Error;
use app\library\PageBase;
use think\Validate;
use think\Cache;

class GetAnnouncement extends PageBase
{

    private $objAnnouncement;

    public function __construct()
    {
        parent::__construct();

        $this->objAnnouncement = new Announcement();
    }

    /**
     * @param $param
     * @return array|bool
     * @DESC 验证接口字段
     */
    public function checkParam($param)
    {
        $rule = [
            'user_id' => 'require',
        ];
        $msg = [
            'user_id.require' => '用户ID',
        ];

        $validate = new Validate($rule, $msg);
        $result = $validate->check($param);
        if (!$result) {
            return $validate->getError();
        }
        return '';
    }

    public function excute($param)
    {
        //$ret = $this->checkToken($param);
        //if (false === $ret) {
        //    return $this->getRes(Error::ERR_SYS);
        //}

        // TODO:业务逻辑
        // 1、参数校验
        $ret = $this->checkParam($param);
        if ($ret) {
            return $this->getRes(Error::ERR_PARAM, $ret);
        }

        $ret = $this->objAnnouncement->getAnnouncement();
        if (false === $ret) {
            return $this->getRes(Error::ERR_SYS);
        }

        return $this->getRes();
    }
}
